/*
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.merak.core;

import java.io.File;
import java.io.IOException;

public class IO {

	//~ Constructors /////////////////////////////////////////////////////////////
	//****************************************************************************
	protected IO() { }

	//~ Methods //////////////////////////////////////////////////////////////////
	//****************************************************************************
	/** Pauses the application until a Key Event is caught (E.g.: Enter key) */
	public void pause() {

		try {
			System.in.read();
		}
		catch(IOException ex) {Application.getLogger().warn(
			"Cannot pause the application: " + ex.getMessage()
		);}

	}
	//****************************************************************************
	/** Pauses the application until a Key Event is caught (E.g.: Enter key) */
	public void pause(String message) {

		try {
			System.out.println(message);
			System.in.read();
		}
		catch(IOException ex) {Application.getLogger().warn(
			"Cannot pause the application: " + ex.getMessage()
		);}

	}
	//****************************************************************************
	public File createDirectory(String path) {

		File file = new File( path );
		if (!file.exists()) file.mkdir();
		return file;

	}
	//****************************************************************************
	public final File createTempFile(String name) throws IOException {

		File tmp = File.createTempFile(
				name,                                  // file name prefix
				null,                                  // file name suffix. Leave it null to allow JVM to create random suffixes.
				Application.paths.temporary.getFile()  // Temporary directory to store temporary files
		);
		tmp.deleteOnExit();
		return tmp;

	}
	//****************************************************************************
	public final File createTempFile(String name,String type) throws IOException {

		File tmp = File.createTempFile(
				name,                                  // file name prefix
				type,                                  // file name suffix.
				Application.paths.temporary.getFile()  // Temporary directory to store temporary files
		);
		tmp.deleteOnExit();
		return tmp;

	}
	//****************************************************************************/

}
